package org.eclipse.rally.plugin.views;

import java.util.Calendar;

import org.eclipse.rally.plugin.utils.CalenderChooser;
import org.eclipse.rally.plugin.utils.SWTResourceManager;
import org.eclipse.rally.plugin.webservice.RallyMain;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.DateTime;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Text;

import com.rallydev.webservice.v1_12.domain.Attachment;
import com.rallydev.webservice.v1_12.domain.Defect;
import com.rallydev.webservice.v1_12.domain.HierarchicalRequirement;
import com.rallydev.webservice.v1_12.domain.Iteration;
import com.rallydev.webservice.v1_12.domain.Project;
import com.rallydev.webservice.v1_12.domain.Release;
/**
 * EditDefectDetailGUI
 * @author Nadeem Khan
 * 
 */

public class EditUserStoryDetailGUI {
    public static Shell shell;
    private static Button button,blocked;
    public static Text lblValue_4; 
    public static Composite composite ;
     public static ScrolledComposite scrolledComposite;
   public static UserStoryDetailGUI dbg;
    public static Group group;
    private static Text revision,text,lblValue_3,attachment,plan_estimate,todo,label_12,task_estimate,actual,attachmenttext,owner;
    public static Browser lblValue_1,lblValue,notes;
    public static CCombo state,project,packagecombo,release,iteration;
    public static HierarchicalRequirement requirement;
    private static Text addnotes;
    public static void main(String[] args) {
        Display display = new Display();
        shell = new Shell(display);
        shell.setMinimumSize(new Point(400, 1200));
        shell.setLayout(new FillLayout());
        int i=1;
        String id = "DE5731";
        TabFolder tabFolder = new TabFolder(shell, SWT.NONE);
        TabItem tbtmIssuedetail = new TabItem(tabFolder, SWT.NONE);
        tbtmIssuedetail.setText("Edit User Story &Detail");
        edituserstoryDetail(tabFolder, tbtmIssuedetail, id, "userStories");
        
        shell.setSize(900, 1000);
        shell.open();

        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }

        display.dispose();
    }

    /*public static void Show()
    {*/
    public static void edituserstoryDetail(final TabFolder tabFolder,final TabItem tabItem, final String userStoryRefrence,final String pageName) 
    {
    
    	try{
    	
    	 requirement = (HierarchicalRequirement) RallyMain.readTaskWorkProdObject(userStoryRefrence);
         scrolledComposite = new ScrolledComposite(tabFolder, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    	tabItem.setControl(scrolledComposite);
    	scrolledComposite.setExpandHorizontal(true);
    	scrolledComposite.setExpandVertical(true);
    	
    	 composite = new Composite(scrolledComposite, SWT.BORDER);
    	composite.setBackground(SWTResourceManager.getColor(SWT.COLOR_LIST_BACKGROUND));
     
        group = new Group(composite, SWT.BORDER);
        group.setBackground(SWTResourceManager.getColor(
                SWT.COLOR_LIST_BACKGROUND));
        group.setBounds(10, 10, 850, 1073);

        {
            Label lblGeneral = new Label(group, SWT.BORDER);
            lblGeneral.setForeground(SWTResourceManager.getColor(
                    SWT.COLOR_WIDGET_BORDER));
            lblGeneral.setBackground(SWTResourceManager.getColor(
                    SWT.COLOR_TITLE_INACTIVE_BACKGROUND));
            lblGeneral.setFont(SWTResourceManager.getFont("Tahoma", 10, SWT.BOLD));
            lblGeneral.setBounds(0, 0, 168, 21);
            lblGeneral.setText("General");

        Label lblId = new Label(group, SWT.BORDER | SWT.RIGHT);
        lblId.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
        lblId.setBounds(0, 20, 166, 21);
        lblId.setText("ID :");
        lblId.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
        lblId.setBackground(SWTResourceManager.getColor(
                SWT.COLOR_TITLE_INACTIVE_FOREGROUND));

        Label lblName = new Label(group, SWT.BORDER | SWT.RIGHT);
        lblName.setBounds(0, 40, 166, 24);
        lblName.setText("Name :");
        lblName.setForeground(SWTResourceManager.getColor(SWT.COLOR_LIST_BACKGROUND));
        lblName.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
        lblName.setBackground(SWTResourceManager.getColor(SWT.COLOR_DARK_RED));

        Label lblDescription = new Label(group, SWT.BORDER | SWT.RIGHT);
        lblDescription.setBounds(0, 63, 166, 250);
        lblDescription.setText("Description:");
        lblDescription.setForeground(SWTResourceManager.getColor(
                SWT.COLOR_BLACK));
        lblDescription.setFont(SWTResourceManager.getFont("Tahoma", 9,
                SWT.NORMAL));
        lblDescription.setBackground(SWTResourceManager.getColor(
                SWT.COLOR_TITLE_INACTIVE_FOREGROUND));

        Label lblAttachments = new Label(group, SWT.BORDER | SWT.RIGHT);
        lblAttachments.setBounds(0, 313, 166, 59);
        lblAttachments.setText("Attachments:");
        lblAttachments.setForeground(SWTResourceManager.getColor(
                SWT.COLOR_BLACK));
        lblAttachments.setFont(SWTResourceManager.getFont("Tahoma", 9,
                SWT.NORMAL));
        lblAttachments.setBackground(SWTResourceManager.getColor(
                SWT.COLOR_TITLE_INACTIVE_FOREGROUND));

        Label lblOwner = new Label(group, SWT.BORDER | SWT.RIGHT);
        lblOwner.setBounds(0, 369, 166, 21);
        lblOwner.setText("Owner:");
        lblOwner.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
        lblOwner.setFont(SWTResourceManager.getFont("Tahoma", 10, SWT.NORMAL));
        lblOwner.setBackground(SWTResourceManager.getColor(
                SWT.COLOR_TITLE_INACTIVE_FOREGROUND));

        Label lblProject = new Label(group, SWT.BORDER | SWT.RIGHT);
        lblProject.setBounds(0, 389, 166, 21);
        lblProject.setText("Project:");
        lblProject.setForeground(SWTResourceManager.getColor(SWT.COLOR_LIST_BACKGROUND));
        lblProject.setFont(SWTResourceManager.getFont("Tahoma", 10, SWT.NORMAL));
        lblProject.setBackground(SWTResourceManager.getColor(SWT.COLOR_DARK_RED));

        {
            Label label = new Label(group, SWT.SEPARATOR | SWT.VERTICAL);
            label.setForeground(SWTResourceManager.getColor(
                    SWT.COLOR_LIST_SELECTION));
            label.setBackground(SWTResourceManager.getColor(
                    SWT.COLOR_LIST_SELECTION));
            label.setBounds(166, 20, 2, 411);
        }

        Label lblDefect = new Label(group, SWT.BORDER);
        lblDefect.setBounds(0, 410, 168, 21);
        lblDefect.setText("User Story");
        lblDefect.setForeground(SWTResourceManager.getColor(
                SWT.COLOR_WIDGET_BORDER));
        lblDefect.setFont(SWTResourceManager.getFont("Tahoma", 10, SWT.BOLD));
        lblDefect.setBackground(SWTResourceManager.getColor(
                SWT.COLOR_TITLE_INACTIVE_BACKGROUND));

        Label lblState = new Label(group, SWT.BORDER | SWT.RIGHT);
        lblState.setBounds(0, 430, 166, 21);
        lblState.setText("Parent:");
        lblState.setForeground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_BORDER));
        lblState.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
        lblState.setBackground(SWTResourceManager.getColor(SWT.COLOR_TITLE_INACTIVE_FOREGROUND));

        Label label = new Label(group, SWT.SEPARATOR);
        label.setBounds(166, 430, 2, 193);
        label.setForeground(SWTResourceManager.getColor(
                SWT.COLOR_LIST_SELECTION));
        label.setBackground(SWTResourceManager.getColor(
                SWT.COLOR_LIST_SELECTION));

        Label lblSchedule = new Label(group, SWT.BORDER);
        lblSchedule.setBounds(0, 450, 168, 21);
        lblSchedule.setText("Schedule");
        lblSchedule.setForeground(SWTResourceManager.getColor(
                SWT.COLOR_WIDGET_BORDER));
        lblSchedule.setFont(SWTResourceManager.getFont("Tahoma", 10, SWT.BOLD));
        lblSchedule.setBackground(SWTResourceManager.getColor(
                SWT.COLOR_TITLE_INACTIVE_BACKGROUND));

        Label lblScheduleState = new Label(group, SWT.BORDER | SWT.RIGHT);
        lblScheduleState.setBounds(0, 470, 166, 23);
        lblScheduleState.setText("Schedule State:");
        lblScheduleState.setForeground(SWTResourceManager.getColor(SWT.COLOR_LIST_BACKGROUND));
        lblScheduleState.setFont(SWTResourceManager.getFont("Tahoma", 9,
                SWT.NORMAL));
        lblScheduleState.setBackground(SWTResourceManager.getColor(SWT.COLOR_DARK_RED));

        Label lblRelease = new Label(group, SWT.BORDER | SWT.RIGHT);
        lblRelease.setBounds(0, 492, 166, 23);
        lblRelease.setText("Release:");
        lblRelease.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
        lblRelease.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
        lblRelease.setBackground(SWTResourceManager.getColor(
                SWT.COLOR_TITLE_INACTIVE_FOREGROUND));

        Label lblPlanEstimate = new Label(group, SWT.BORDER | SWT.RIGHT);
        lblPlanEstimate.setBounds(0, 514, 166, 23);
        lblPlanEstimate.setText("Plan Estimate:");
        lblPlanEstimate.setForeground(SWTResourceManager.getColor(
                SWT.COLOR_BLACK));
        lblPlanEstimate.setFont(SWTResourceManager.getFont("Tahoma", 9,
                SWT.NORMAL));
        lblPlanEstimate.setBackground(SWTResourceManager.getColor(
                SWT.COLOR_TITLE_INACTIVE_FOREGROUND));

        Label lblToDo = new Label(group, SWT.BORDER | SWT.RIGHT);
        lblToDo.setBounds(0, 536, 166, 23);
        lblToDo.setText("To Do:");
        lblToDo.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
        lblToDo.setFont(SWTResourceManager.getFont("Tahoma", 10, SWT.NORMAL));
        lblToDo.setBackground(SWTResourceManager.getColor(
                SWT.COLOR_TITLE_INACTIVE_FOREGROUND));

        Label lblActual = new Label(group, SWT.BORDER | SWT.RIGHT);
        lblActual.setBounds(0, 559, 166, 21);
        lblActual.setText("Actual:");
        lblActual.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
        lblActual.setFont(SWTResourceManager.getFont("Tahoma", 10, SWT.NORMAL));
        lblActual.setBackground(SWTResourceManager.getColor(
                SWT.COLOR_TITLE_INACTIVE_FOREGROUND));

        lblValue_1 = new Browser(group, SWT.BORDER);
        
		lblValue_1.setBounds(172, 40, 672, 21);
		System.out.println("Nameeeee   = "+requirement.getName());
		if(requirement.getName() != null)
			
			lblValue_1.setText(requirement.getName());
			else
				lblValue_1.setText("");
		lblValue_1.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
		lblValue_1.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
		lblValue_1.setBackground(SWTResourceManager.getColor(SWT.COLOR_LIST_BACKGROUND));

       
      
		lblValue = new Browser(group, SWT.BORDER );
	
		lblValue.setBounds(172, 63, 672, 244);
		if(requirement.getDescription() != null){
		String description = 	requirement.getDescription().replace("<br>","\n\n");
		lblValue.setText(description);
		}else
			lblValue.setText("");
	
		lblValue.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
		lblValue.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
		lblValue.setBackground(SWTResourceManager
				.getColor(SWT.COLOR_LIST_BACKGROUND));
		
      attachmenttext = new Text(group, SWT.BORDER | SWT.LEFT);
      attachmenttext.setBounds(172, 313, 672, 21);
       
      attachmenttext.setText("Sreekanth");
      attachmenttext.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
        attachmenttext.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
        attachmenttext.setBackground(SWTResourceManager.getColor(
                SWT.COLOR_LIST_BACKGROUND));

        owner = new Text(group, SWT.BORDER);
        owner.setBounds(172, 369, 166, 21);
        if(requirement.getOwner() != null)
    		owner.setText(requirement.getOwner());
    		else
    			owner.setText("");	
        owner.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
        owner.setFont(SWTResourceManager.getFont("Tahoma", 10, SWT.NORMAL));
        owner.setBackground(SWTResourceManager.getColor(
                SWT.COLOR_LIST_BACKGROUND));
        
	    attachment = new Text(group, SWT.BORDER);
		attachment.setBounds(172, 346, 286, 19);
                {
		Button btnBrowse = new Button(group, SWT.NONE);
		btnBrowse.setBounds(476, 346, 68, 20);
		btnBrowse.setText("Browse");
		
		btnBrowse.addListener(SWT.Selection, new Listener() {
		      public void handleEvent(Event event) {
		    	final Shell dialog = new Shell (shell, SWT.DIALOG_TRIM);
		        FileDialog fileDialog = new FileDialog(dialog, SWT.MULTI);
		        String fileFilterPath = "F:/jdk1.5";
		        fileDialog.setFilterPath(fileFilterPath);
		        
		        fileDialog.setFilterExtensions(new String[]{"*.rtf", "*.html", "*.*"});
		        fileDialog.setFilterNames(new String[]{ "Rich Text Format", "HTML Document", "Any"});
		        
		        String firstFile = fileDialog.open();

		        if(firstFile != null) {
		          fileFilterPath = fileDialog.getFilterPath();
		          String[] selectedFiles = fileDialog.getFileNames();
		          StringBuffer sb = new StringBuffer(fileDialog.getFilterPath());
		          for(int i=0; i<selectedFiles.length; i++) {
		            sb.append(selectedFiles[i]);
		          }
		          attachment.setText(sb.toString());
		        }
		        dialog.pack();
			    dialog.open();
			    dialog.close();
		      }
		      
		    });
		
		  }
       
        

        plan_estimate = new Text(group, SWT.BORDER | SWT.BORDER);
        plan_estimate.setBounds(172, 514, 166, 21);
        if (requirement.getPlanEstimate() != null)
			plan_estimate.setText(String.valueOf(requirement.getPlanEstimate()));
		else
			plan_estimate.setText("");
        plan_estimate.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
        plan_estimate.setFont(SWTResourceManager.getFont("Tahoma", 10, SWT.NORMAL));
        plan_estimate.setBackground(SWTResourceManager.getColor(
                SWT.COLOR_LIST_BACKGROUND));

        todo = new Text(group, SWT.BORDER | SWT.BORDER);
        todo.setBounds(172, 536, 166, 21);
        todo.setText("To do");
        todo.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
        todo.setFont(SWTResourceManager.getFont("Tahoma", 10, SWT.NORMAL));
        todo.setBackground(SWTResourceManager.getColor(
                SWT.COLOR_LIST_BACKGROUND));

        actual = new Text(group, SWT.BORDER | SWT.BORDER);
        actual.setBounds(172, 559, 166, 21);
        if(requirement.getAcceptedDate() != null)
        	actual.setText(""+requirement.getAcceptedDate());
    		else
    			actual.setText("");
        actual.setText("Actual");
        actual.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
        actual.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
        actual.setBackground(SWTResourceManager.getColor(
                SWT.COLOR_LIST_BACKGROUND));
       
      
        Label label_27 = new Label(group, SWT.RIGHT);
        label_27.setBounds(172, 20, 166, 20);
        if(requirement.getFormattedID() != null)
    		label_27.setText(requirement.getFormattedID());
    		else
    			label_27.setText("");	
        label_27.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
        label_27.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
        label_27.setBackground(SWTResourceManager.getColor(
                SWT.COLOR_LIST_BACKGROUND));
        label_27.setAlignment(SWT.LEFT);

        Label label_28 = new Label(group, SWT.BORDER);
        label_28.setBounds(160, 427, 800, 3);
        label_28.setForeground(SWTResourceManager.getColor(
                SWT.COLOR_WIDGET_BORDER));
        label_28.setFont(SWTResourceManager.getFont("Times New Roman", 13,
                SWT.BOLD));
        label_28.setBackground(SWTResourceManager.getColor(
                SWT.COLOR_TITLE_INACTIVE_BACKGROUND));

        Label label_29 = new Label(group, SWT.BORDER);
        label_29.setBounds(160, 468, 800, 3);
        label_29.setForeground(SWTResourceManager.getColor(
                SWT.COLOR_WIDGET_BORDER));
        label_29.setFont(SWTResourceManager.getFont("Times New Roman", 13,
                SWT.BOLD));
        label_29.setBackground(SWTResourceManager.getColor(
                SWT.COLOR_TITLE_INACTIVE_BACKGROUND));

        Label lblBlocked = new Label(group, SWT.BORDER | SWT.RIGHT);
        lblBlocked.setBounds(444, 470, 166, 21);
        lblBlocked.setText("Blocked:");
        lblBlocked.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
        lblBlocked.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
        lblBlocked.setBackground(SWTResourceManager.getColor(
                SWT.COLOR_TITLE_INACTIVE_FOREGROUND));

        Label lblIteration = new Label(group, SWT.BORDER | SWT.RIGHT);
        lblIteration.setBounds(444, 490, 166, 21);
        lblIteration.setText("Iteration:");
        lblIteration.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
        lblIteration.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
        lblIteration.setBackground(SWTResourceManager.getColor(
                SWT.COLOR_TITLE_INACTIVE_FOREGROUND));

        Label lblTaskEstimate = new Label(group, SWT.BORDER | SWT.RIGHT);
        lblTaskEstimate.setBounds(444, 510, 166, 21);
        lblTaskEstimate.setText("Task Estimate:");
        lblTaskEstimate.setForeground(SWTResourceManager.getColor(
                SWT.COLOR_BLACK));
        lblTaskEstimate.setFont(SWTResourceManager.getFont("Tahoma", 9,
                SWT.NORMAL));
        lblTaskEstimate.setBackground(SWTResourceManager.getColor(
                SWT.COLOR_TITLE_INACTIVE_FOREGROUND));
         task_estimate = new Text(group, SWT.BORDER | SWT.BORDER);
         task_estimate.setBounds(615, 510, 166, 21);
        if(requirement.getTaskEstimateTotal()!= null)
        	task_estimate.setText(String.valueOf(requirement.getTaskEstimateTotal()));
    		else
    			task_estimate.setText("");
        task_estimate.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
        task_estimate.setFont(SWTResourceManager.getFont("Tahoma", 10, SWT.NORMAL));
        task_estimate.setBackground(SWTResourceManager.getColor(
                SWT.COLOR_LIST_BACKGROUND));

        Label label_34 = new Label(group, SWT.SEPARATOR);
        label_34.setBounds(610, 470, 2, 61);
        label_34.setForeground(SWTResourceManager.getColor(
                SWT.COLOR_LIST_SELECTION));
        label_34.setBackground(SWTResourceManager.getColor(
                SWT.COLOR_LIST_SELECTION));
      
        	
        Label lblNotes = new Label(group, SWT.BORDER);
        lblNotes.setBounds(0, 579, 168, 21);
        lblNotes.setText("Notes");
        lblNotes.setForeground(SWTResourceManager.getColor(
                SWT.COLOR_WIDGET_BORDER));
        lblNotes.setFont(SWTResourceManager.getFont("Tahoma", 10, SWT.BOLD));
        lblNotes.setBackground(SWTResourceManager.getColor(
                SWT.COLOR_TITLE_INACTIVE_BACKGROUND));

        Label label_35 = new Label(group, SWT.BORDER);
        label_35.setBounds(160, 594, 800, 3);
        label_35.setForeground(SWTResourceManager.getColor(
                SWT.COLOR_WIDGET_BORDER));
        label_35.setFont(SWTResourceManager.getFont("Times New Roman", 13,
                SWT.BOLD));
        label_35.setBackground(SWTResourceManager.getColor(
                SWT.COLOR_TITLE_INACTIVE_BACKGROUND));
    

        Label lblNotes_1 = new Label(group, SWT.BORDER | SWT.RIGHT);
        lblNotes_1.setBounds(0, 599, 166, 323);
        lblNotes_1.setText("Notes :");
        lblNotes_1.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
        lblNotes_1.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
        lblNotes_1.setBackground(SWTResourceManager.getColor(
                SWT.COLOR_TITLE_INACTIVE_FOREGROUND));

        Label label_39 = new Label(group, SWT.SEPARATOR);
        label_39.setBounds(166, 606, 2, 417);
        label_39.setForeground(SWTResourceManager.getColor(
                SWT.COLOR_LIST_SELECTION));
        label_39.setBackground(SWTResourceManager.getColor(
                SWT.COLOR_LIST_SELECTION));
        notes = new Browser(group, SWT.BORDER);
      
        notes.setBounds(172, 598, 672, 323);
       
        if(requirement.getNotes()!= null)
        	notes.setText(requirement.getNotes());
    		else
    			notes.setText("");
	
		notes.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
		notes.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
		notes.setBackground(SWTResourceManager
				.getColor(SWT.COLOR_LIST_BACKGROUND));

        {
        	final Label back = new Label(group, SWT.NONE);
        	back.setBackground(SWTResourceManager.getColor(
                    SWT.COLOR_TITLE_INACTIVE_BACKGROUND));
        	back.setImage(SWTResourceManager.getImage(EditUserStoryDetailGUI.class, "/icons/Back-enabled.gif"));
        	back.setBounds(794, 0, 50, 19);
        	back.addMouseTrackListener(new MouseTrackAdapter() {
				@Override
				public void mouseHover(MouseEvent e) {
					final Cursor cursor = new Cursor(Display.getCurrent(),
							SWT.CURSOR_HAND);

					back.setCursor(cursor);

				}
			});
        	back.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseDown(MouseEvent e) {
                    composite.dispose();
                    group.dispose();
                    int i=2;
                    	dbg =new UserStoryDetailGUI();//.
                    dbg.userStoryDetail(tabFolder, tabItem, userStoryRefrence, pageName);
                
                   
                    }
			});
        }
               
        Label lblAddNote = new Label(group, SWT.BORDER | SWT.RIGHT);
        lblAddNote.setBounds(0, 922, 166, 41);
        lblAddNote.setText("Add Note :");
        lblAddNote.setForeground(SWTResourceManager.getColor(0, 0, 0));
        lblAddNote.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
        lblAddNote.setBackground(SWTResourceManager.getColor(216, 228, 248));
        
        Label label_01 = new Label(group, SWT.NONE);
        label_01.setBackground(SWTResourceManager.getColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND));
        label_01.setBounds(2, 1021, 166, 2);
        
        Label lblAddRevision = new Label(group, SWT.BORDER);
        lblAddRevision.setBounds(0, 959, 168, 21);
        lblAddRevision.setText("Revision");
        lblAddRevision.setForeground(SWTResourceManager.getColor(0, 0, 0));
        lblAddRevision.setFont(SWTResourceManager.getFont("Tahoma", 10, SWT.BOLD));
        lblAddRevision.setBackground(SWTResourceManager.getColor(122, 150, 223));
        
        Label line_4 = new Label(group, SWT.BORDER);
        line_4.setBounds(160, 974, 800, 3);
        line_4.setForeground(SWTResourceManager.getColor(0, 0, 0));
        line_4.setFont(SWTResourceManager.getFont("Times New Roman", 13, SWT.BOLD));
        line_4.setBackground(SWTResourceManager.getColor(122, 150, 223));
        
        revision = new Text(group, SWT.BORDER);
        revision.setBounds(172, 983, 672, 41);
        revision.setBackground(SWTResourceManager.getColor(SWT.COLOR_LIST_BACKGROUND));
        {
        	final Button btnSubmit = new Button(group, SWT.NONE);
        	btnSubmit.setBounds(456, 1030, 68, 23);
        	btnSubmit.setText("Submit");
        	btnSubmit.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseDown(MouseEvent e) {
               	 System.out.println("in submit()");
               	 try{
               		editUserStoryDetails();
               	 composite.dispose();
                 group.dispose();
                 int i=2;
                 dbg =new UserStoryDetailGUI();
                 dbg.userStoryDetail(tabFolder, tabItem, userStoryRefrence, pageName);
               	 }catch (Exception e1) {
						e1.printStackTrace();
					}
               	 System.out.println("End of submit()");
                }
            });
        }
        
        text = new Text(group, SWT.BORDER);
        text.setBounds(172, 1261, 672, 41);
        text.setBackground(SWTResourceManager.getColor(SWT.COLOR_LIST_BACKGROUND));
        Label lblChangeDescription = new Label(group, SWT.BORDER | SWT.RIGHT);
        lblChangeDescription.setBounds(0, 978, 166, 46);
        lblChangeDescription.setText("Change Description:");
        lblChangeDescription.setForeground(SWTResourceManager.getColor(0, 0, 0));
        lblChangeDescription.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
        lblChangeDescription.setBackground(SWTResourceManager.getColor(216, 228, 248));
        
        }
    	
    	{
            project = new CCombo(group, SWT.BORDER);
        	project.setItems(new String[] {"LoanPath"});
        	project.setBounds(172, 392, 166, 21);
        }
        {
        	Label lblPackage = new Label(group, SWT.BORDER | SWT.RIGHT);
        	lblPackage.setBounds(444, 369, 166, 21);
        	lblPackage.setText("Package:");
        	lblPackage.setForeground(SWTResourceManager.getColor(0, 0, 0));
        	lblPackage.setFont(SWTResourceManager.getFont("Tahoma", 9, SWT.NORMAL));
        	lblPackage.setBackground(SWTResourceManager.getColor(216, 228, 248));
        }
        {
        	packagecombo = new CCombo(group, SWT.BORDER);
        	packagecombo.setBounds(615, 369, 166, 21);
        	packagecombo.setItems(new String[] {"TUS-Configuration tab", "TUS-Doc Mgmt.", "TUS-DD"});
        }
        {
            state = new CCombo(group, SWT.BORDER);
        	state.setBounds(172, 470, 93, 21);
        	state.setItems(new String[] {"Completed", "Defined", "In-progess", "Accepted", "", ""});
        }
        {
            release = new CCombo(group, SWT.BORDER);
        	release.setBounds(172, 492, 93, 21);
        	release.setItems(new String[] {"Unscheduled", "Realse 1.0", "Realse 1.2", "Realse 1.1", "Realse 2.0", ""});
        }
        {
        	iteration = new CCombo(group, SWT.BORDER);
        	iteration.setBounds(615, 487, 166, 21);
        	iteration.setItems(new String[] {"Unscheduled", "Post RC15 Unscheduled Trunk Fixes"});
        }
        {
            blocked = new Button(group, SWT.CHECK);
        	blocked.setBounds(615, 470, 13, 16);
        	blocked.setSelection(true);
        }
        
        Label label = new Label(group, SWT.NONE);
        label.setBounds(165, 0, 684, 20);
        label.setBackground(SWTResourceManager.getColor(122, 150, 223));
        
        addnotes = new Text(group, SWT.BORDER);
        addnotes.setBounds(172, 927, 672, 41);
        addnotes.setBackground(SWTResourceManager.getColor(255, 255, 255));
        
    	
    	
        scrolledComposite.setContent(composite);
    	scrolledComposite.setMinSize(new Point(859, 1100));
        
        }catch(Exception e){
        	e.printStackTrace();
        }
        
      
    }
    private static void editUserStoryDetails(){
    	System.out.println("defect=="+requirement);
    	if(requirement != null){
    		System.out.println("in editDefectDetails method");
    		if(packagecombo.getText() != null && packagecombo.getText().trim().length() > 0){
    			System.out.println("packagecombo.getText()=="+packagecombo.getText());
    			requirement.set_package(packagecombo.getText());
    		}
    		
    		if(owner.getText() != null && owner.getText().length() > 0){
    			requirement.setOwner(owner.getText());
    		}
    		/*if(project.getText() != null && project.getText().trim().length() > 0){
    			Project projt=new Project();
    			projt.setName(project.getText());
    			requirement.setProject(projt);
    		}*/
    		if(state.getText() != null && state.getText().trim().length() > 0){
    			requirement.setScheduleState(state.getText());
    			
    		}
    		/*Release rel=new Release();
    		rel.setName(release.getText());
    		if(release.getText() != null && release.getText().trim().length() > 0){
			requirement.setRelease(rel);
			}*/
    		
    	/*	if(iteration.getText() != null && iteration.getText().trim().length() > 0){
    			System.out.println("target_build.getText()=="+iteration.getText());
    			requirement.setIteration((HierarchicalRequirement)iteration.getText());
    		}*/
    		if(blocked.getText() != null && blocked.getText().trim().length() > 0){
    			requirement.setBlocked(blocked.getSelection());
    		}
    	
    		if(task_estimate.getText() != null && task_estimate.getText().trim().length() > 0){
    			requirement.setPlanEstimate(new Double(task_estimate.getText()));
    		}
    		
    		//if(attachment.getText() != null && attachment.getText().trim().length() > 0){
    			//defect.setRootCause(root_cause.getText());
    			/*try {
					Attachment attachments[] = new Attachment[getBytesFromFile(imgfile).length];
					AttachmentContent con = new AttachmentContent();
					con.setContent(getBytesFromFile(imgfile));
					int count = 1;
			         for(Object obj:attachments){
			         	Attachment attach = (Attachment)obj;
			         	//attach = (Attachment)RallyMain.readAttachemntObject(attach.getRef());
			         	//attach.setContentType("text/html");
			         	count ++;
			         }
			     
					//Attachment att=new Attachment();
					//att.setContentType("text/html;charset=utf-8");
					defect.setAttachments(attachments);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}*/
    			
    			//defect.setAttachments(attachments)
    	//	}
    		if(addnotes.getText() != null && addnotes.getText().trim().length() > 0){
    			 java.util.GregorianCalendar calendar = new java.util.GregorianCalendar();
    	            String date = String.valueOf(calendar.get(Calendar.DATE));
    	            String month = String.valueOf(calendar.get(Calendar.MONTH));
    	            String year = String.valueOf(calendar.get(Calendar.YEAR));
    	            String hour = String.valueOf(calendar.get(Calendar.HOUR));
    	            String minute = String.valueOf(calendar.get(Calendar.MINUTE));
    	            String second = String.valueOf(calendar.get(Calendar.SECOND));
    	            
    	            String timeStamp = date+"/"+month+"/"+year+"::"+hour+":"+minute+":"+second;
    	            String user = HeaderPage.userNameFromRally;
    	    		String defectNotes = " ["+timeStamp+" "+user+"]:"+addnotes.getText() +" <br>";
    	    		defectNotes += requirement.getNotes();
    	    		requirement.setNotes(defectNotes);
    	    		
    		}
    		/*if(revision.getText() != null && revision.getText().trim().length() > 0){
    			requirement.setRevisionHistory(revisionHistory);
    		}*/
    		
    	    RallyMain.updateObject(requirement);
    		
    	}
    	
    }   
}
